from selenium import webdriver
import time
import datetime


def daka(username,password):

    # 获取当前24小时时间
    now_time = datetime.datetime.now()
    hour = int(datetime.datetime.now().strftime('%H'))

    driver = webdriver.Chrome()
    driver.get("httpxxxx")#网址
    now_handle = driver.current_window_handle
    driver.switch_to.window(now_handle)
    driver.find_element_by_id("un").clear()
    driver.find_element_by_id("pd").clear()
    driver.find_element_by_id("un").send_keys(username)	# 账号
    driver.find_element_by_id("pd").send_keys(password)	# 密码
    driver.find_element_by_id('index_login_btn').click()
    # 七点到九点
    if(7<=hour<9):
        # 早
        try:
            driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div/div/span').click()
            driver.find_element_by_xpath('//*[@id="app"]/form/div[5]/input').click()
        except Exception as e:
            pass
    # 12点到14点
    elif(12<=hour<14):
        # 中
        try:
            driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/div/div/span').click()
            driver.find_element_by_xpath('//*[@id="app"]/form/div[5]/input').click()
        except Exception as e:
            pass
    # 17点到21点
    elif(19<=hour<21):
        # 晚
        try:
            driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[3]/div/div/span').click()
            driver.find_element_by_xpath('//*[@id="app"]/form/div[5]/input').click()
        except Exception as e:
            pass

    time.sleep(1)
    # 每日上报
    driver.get("https:xxxx")#请一个网址
    driver.find_element_by_xpath('//*[@id="collapseOne"]/div[1]/div/div/div/label[1]/span[2]').click()
    driver.find_element_by_xpath('//*[@id="shentizhuangkuang"]/div/div/div/label[1]/span[2]').click()
    driver.find_element_by_xpath('//*[@id="Travels"]/ul/li[1]/div[2]/div/div/div/label[1]/span[2]').click()
    driver.find_element_by_xpath('//*[@id="collapseOne"]/div[3]/button').click()
    driver.close()





if __name__ == '__main__':
    username = "000000"
    password = "xxxxxx"
    daka(username,password)
